﻿using System.Configuration;

namespace Excel4DB.Util
{
    public class ConfigHelper
    {
        private static ConfigHelper _instance;
        private static object objLock = new object();
        private ConfigHelper() { }
        public static ConfigHelper Instance
        {
            get
            {
                if (_instance==null)
                {
                    lock (objLock)
                    {
                        if(_instance==null)
                        {
                            _instance = new ConfigHelper();
                        }
                    }
                }
                return _instance;
            }
        }
        public string ServerAddress { get; set; }

        public string ServerPort { get; set; }

        public string Account { get; set; }

        public string Pwd { get; set; }

        public string ConStr
        {
            get
            {
                string conStr = $"Data Source={ServerAddress};";
                if (string.IsNullOrWhiteSpace(Account))
                {
                    conStr += "Integrated Security=True;";
                }
                else
                {
                    conStr += $"user={Account};pwd={Pwd};";
                }
                if (!string.IsNullOrWhiteSpace(DBName))
                {
                    conStr += $"initial catalog={DBName};";
                }
                return conStr;
            }
        }

        public string DBName { get; set; }
        public string DbType=> ConfigurationManager.AppSettings[nameof(DbType)];
    }
}
